//单页长时间不操作就会自动退出

let lastTime = new Date().getTime()
let currentTime = new Date().getTime()
const timeOut = 2 * 60 * 1000

window.onload = function() {
  window.document.onmousedown = function() {
    localStorage.setItem('lastTime', new Date().getTime())
  }
}

function checkTimeout() {
  currentTime = new Date().getTime()		//更新当前时间
  lastTime = localStorage.getItem('lastTime')
  if (currentTime - lastTime > timeOut) {//判断是否超时
    console.log('超时')
    let url = window.location.href
    let newUrl = url.match(/(\S*)#/)
    sessionStorage.clear()
    window.sessionStorage.clear()
    window.open('/', '_self')
  }
}

/* 定时器 间隔30秒检测是否长时间未操作页面 */
setInterval(checkTimeout, 30000)